﻿/*----------------------------------------------------------------
    // Copyright (C) 2009 江苏华招网
    // 版权所有。 
    // 作者：吕海乐 
    //
    // 文件名：MessageList.aspx.cs
    // 文件功能描述：消息管理：消息和公告列表
    // 创建标识：吕海乐2009-5-20
    //
    // 修改标识：
    // 修改描述：
    //
    // 修改标识：
    // 修改描述：
    //
    // 审核人：
// 审核时间：
// 审核说明：
 //----------------------------------------------------------------*/
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using HZ.DrugTrade.Model;
using HZ.DrugTrade.IBLL;
using HZ.DrugTrade.BLLFactory;

namespace HZ.DrugTrade.Web.Enterprise.MessageMange
{
    public partial class MessageList : BasePage
    {
        public MessageList()
        {
            this.ModuleNo = "";
        }

        public static string Tip;
        IBLL_Message im = Factory.BLL_Message();

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                SetBind();
            }
        }

        /// <summary>
        /// 绑定所有发出的消息
        /// </summary>
        private void SetBind()
        {
            if (!string.IsNullOrEmpty(Request.QueryString["flag"]))
            {
                string flag = Request.QueryString["flag"];
                int temp;
                //AspNetPager1.PageSize = Constants.GRIDVIEW_PAGE_SIZE;
                if (flag == "1")
                {
                    btnDel.Visible = true;
                    gvwMsgList.Visible = true;
                    Tip = "消息列表";
                    IList<Model.View.Message> lstMessage = im.GetMessage(new Model.Query.Message() { SortFields = "SendTime DESC" }, AspNetPager1.CurrentPageIndex, AspNetPager1.PageSize, out temp);
                    gvwMsgList.DataSource = lstMessage;
                    gvwMsgList.DataBind();
                }
                else if (flag == "2")
                {
                    gvwNotice.Visible = true;
                    Tip = "公告列表";
                    IList<Model.View.Notice> lstNotice = im.GetNotice(new Model.Query.Notice() { SortFields = "SendTime DESC" }, AspNetPager1.CurrentPageIndex, AspNetPager1.PageSize, out temp);
                    gvwNotice.DataSource = lstNotice;
                    gvwNotice.DataBind();
                }
            }
        }

        /// <summary>
        /// 绑定信息的状态
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void gvwMsgList_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                Literal ltrStatus = e.Row.FindControl("ltrStatus") as Literal;
                if (ltrStatus.Text == "0")
                {
                    ltrStatus.Text = "未阅读";
                }
                else if (ltrStatus.Text == "1")
                {
                    ltrStatus.Text = "已阅读";
                }
                else if (ltrStatus.Text == "2")
                {
                    ltrStatus.Text = "已回复";
                }
            }
        }

        /// <summary>
        /// 翻页
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void AspNetPager1_OnPageChanged(object sender, EventArgs e)
        {
            SetBind();
        }

        /// <summary>
        /// 删除消息
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnDel_Click(object sender, EventArgs e)
        {
            IList<Message> lstMsg = new List<Message>();
            string Mid = Request["chkChildUser"];
            if (!string.IsNullOrEmpty(Mid))
            {
                string[] arrayMsg = Mid.Split(',');
                foreach (string item in arrayMsg)
                {
                    Message aMsg = new Message();
                    aMsg.MessageID = item;
                    lstMsg.Add(aMsg);
                }

                int flag = im.DeleteMessage_Batch(lstMsg);
                if (flag == 1)
                {
                    PageInfo("删除成功！", this.ReturnUrl);
                }
                else
                {
                    PageError("删除失败！", this.ReturnUrl);
                }
            }
        }
    }
}
